<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>管理系统-左侧菜单</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<script src="<%=request.getContextPath() %>/docs/login/leftTree/prototype.lite.js" type="text/javascript"></script>
<script src="<%=request.getContextPath() %>/docs/login/leftTree/moo.fx.js" type="text/javascript"></script>
<script src="<%=request.getContextPath() %>/docs/login/leftTree/moo.fx.pack.js" type="text/javascript"></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/comdwr.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/util.js'></script>
<%--<link href="<%=request.getContextPath() %>/docs/login/img/main.css" rel="stylesheet" type="text/css" />--%>
<link href="<%=request.getContextPath() %>/docs/login/img/tree.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
//获取上页传过来的值,进行拆分,调用dwr
window.onload = function() {
	comdwr.getLeft(callBack) ;
}

//回调函数,从session中取得角色id,进行查询与权限进行匹配
function callBack(object) {
	//alert(object.length);
	if(object.length == 0)
	{
		alert("本页暂时还没有可以访问的数据,请联系管理员aa") ;
		this.parent.location = '<%=request.getContextPath()%>/index.jsp' ;
	}
	else
	{
		//通过manager的id来获取权限
		//通过manager的id来获取权限
		showTable(object,'${sessionScope.admin_user.gramaid}');
		
	}
	
}
//根据不同角色显示左树
function showTable(object,role) {
	var mf = '<%=request.getContextPath() %>';
	var show = '<%=request.getParameter("show")%>' ;
	//判断是否加上工程名
	if(show == "0")
	{
		mf = "" ; 
	} 

	//session中取得数据
	
	var session = role ;
	var tree = new Array();
	tree = session.split(",") ;
	
	var ul, li, a, diva, divb, divc, divd, span ,flag;
	
	//记录用户是否有浏览本页的权限
	var flaga = false ;		 
	
	//控制开关
	flag = false ;
	var ac = $("container") ;
	var p = 0 ;
	//分别取得父类树
	var fTree = object[0] ;
	var i = 0 ;
	//alert("object.length="+object.length);
	//debugger;
	for(var j = 1 ;j < object.length ; j ++) {
		var sTree = object[j] ;
		diva = document.createElement("H1");
		divb = document.createElement("div");
		divc = document.createElement("div");
		ul = document.createElement("ul");
		diva.className = "title";
		var parentlink="";
		//根据控制开关判断是否是该子类树是不是第一次加载,将父类标题加载到div上
		if(!flag) {
			//加载父类
			for(var q = 0 ; q < fTree.length ; q ++) {
				if(sTree == null || sTree == '') {
					continue ;
				}
				if(sTree[q].parentId == fTree[p].id ) {
					parentlink = fTree[p].id;
					diva.innerHTML = "<A href='javascript:void(0)'>"+ fTree[p].nodeName +"</a>";
					break ;
				}
			}
		}
		divb.className="content";
		divc.className="sidebar";
		//遍历2组数中的相同部分,有相同的则加载到div上,并且打开控制开关flag加载大的父类标题
		for(var k = 0 ; k < sTree.length ; k ++ ) {
			for(var c = 0 ; c < tree.length ; c ++  ) {
				//判断用户权限-------------------------------------------------------------------------
				if(sTree[k].id == tree[c]) {
					//alert("sTree[k].id="+sTree[k].id);
					//alert("tree[c]="+tree[c]);
					li = document.createElement("li");
					a = document.createElement("a");
					span = document.createElement("span");
					if(sTree[k].link == "#"){
						a.href = "#";
					}else{
						//alert(sTree[k].link);//数据库中存的内容
						//alert(mf);//     /项目名称
						if(sTree[k].link.indexOf("http://")!=-1){
							a.href = sTree[k].link;
						}else{
							a.href = mf + sTree[k].link;
						}
						if(a.href.indexOf("?")!=-1){
							a.href += "&";
						}else{
							a.href += "?";
						}
						a.href += "parentlink=" +encodeURIComponent(parentlink)+ "&sonlink=" +encodeURIComponent(sTree[k].id);
					}
					a.target = "mainArea" ;
					span.innerHTML = "<img src='img/menu_bt"+i+".gif' width='32' height='32' border='0' /><br />" +sTree[k].nodeName;
					a.appendChild(span);
					li.appendChild(a);
					ul.appendChild(li);
					//控制开关
					flag = true ;
					flaga = true ;
					i++ ;
					break ;
				}else{
					//alert("不等");
				}
			}
		}
		//根据flag 判定父类树下是否有子类树,有则加载,无则不加载
		if(flag) {
			divc.appendChild(ul);
			divb.appendChild(divc);
			ac.appendChild(diva);
			ac.appendChild(divb);
		}
		//重置控制开关
		flag = false ;
		p ++ ;
	}
	
	if(!flaga) {
		alert("您暂时还没有浏览本页面的权限,请联系管理员");
		
		if(screen.height > 1000) {
			this.parent.location = '<%=request.getContextPath()%>/index.jsp' ;
		} else {
			this.parent.location = '<%=request.getContextPath()%>/index.jsp' ;
		}
		
	}
	//js下拉菜单.
	var contents = document.getElementsByClassName('content');
	var toggles = document.getElementsByClassName('title');

	var myAccordion = new fx.Accordion(toggles, contents, {opacity: true, duration: 400});
	myAccordion.showThisHideOpen(contents[0]);
}
</script>
</head>
<body >
	<div id="container" >
	</div>
</body>
</html>
